package cn.flying.cloud.auth.security.captcha;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.web.authentication.WebAuthenticationDetails;

import cn.flying.cloud.base.common.constants.Constants;
import cn.flying.cloud.base.common.utils.Ft;
import cn.flying.cloud.base.redis.service.RedisService;

/**
 * 用于获取用户登录时（除了用户密码以外的）携带的额外信息
 *
 * @author: admin
 * @date: 2023年05月26日 13:06
 * @version: 1.0
 */
public class CaptchaWebAuthenticationDetails extends WebAuthenticationDetails {
    private boolean isPassed;

    public CaptchaWebAuthenticationDetails(HttpServletRequest request, RedisService redisService) {
        super(request);
        String captcha = request.getParameter("captcha");
        String uid = request.getParameter("uid");
        String code = (String) redisService.get(Constants.AUTH_CODE + ":captcha:" + uid);
        if (Ft.String.isNotBlank(captcha) && Ft.String.isNotBlank(code) && captcha.equalsIgnoreCase(code)) {
            isPassed = true;
        }
    }

    public boolean isPassed() {
        return isPassed;
    }

    public void setPassed(boolean passed) {
        isPassed = passed;
    }
}